// ARM ONLY
// Thanks to calc84maniac, Goplat, and jacobly for helping me with this part of the code!

#ifndef _ARMSETJMP_H
#define _ARMSETJMP_H

// Define jmp_buf
typedef int jmp_buf[10];

// longjmp(jmp_buf env, int value)
// Prototype
void longjmp(jmp_buf env, int value) __attribute__ ((naked));

void longjmp(jmp_buf env, int value) {
	__asm__ __volatile__ (
		"ldmia r0,{r4-r11,sp-lr}\n\t"
		"movs r0,r1\n\t"
		"moveq r0,#1\n\t"
		"bx lr\t"
	);
}

// longjmp(jmp_buf env, int value)
// Prototype
int setjmp(jmp_buf env) __attribute__ ((naked));

int setjmp(jmp_buf env) {
	__asm __volatile__ (
		"stmia r0, {r4-r11,sp-lr}\n\t"
		"mov r0, #0\n\t"
		"bx lr\t"
	);
}

#endif
